package com.xiaoyu.izf.model;

import cn.hutool.core.date.DateUtil;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import javax.persistence.*;
import java.sql.Timestamp;
import java.util.Objects;

@Entity
@Table(name = "vip_order", schema = "izf", catalog = "")
public class VipOrder {
    private String id;
    private Integer uid;
    private Integer vipType;
    private Integer orderStatus;
    private String outTradeNo;
    private Timestamp insertTime;
    private Timestamp payTime;
    private Integer totAmount = 0;
    private Integer pushUid = 0;
    private Integer pushSplit = 0;
    private Integer pushAmount = 0;
    private Integer gradePushUid = 0;
    private Integer gradeSplit = 0;
    private Integer gradeAmount = 0;
    private Integer type = 0;
    private Integer isTest;


    private UserInfo buyUser;
    private String insertTimeStr;
    private UserInfo pushUser;
    private UserInfo gradeUser;


    @Id
    @Column(name = "id")
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @Basic
    @Column(name = "uid")
    public Integer getUid() {
        return uid;
    }

    public void setUid(Integer uid) {
        this.uid = uid;
    }

    @Basic
    @Column(name = "vip_type")
    public Integer getVipType() {
        return vipType;
    }

    public void setVipType(Integer vipType) {
        this.vipType = vipType;
    }

    @Basic
    @Column(name = "order_status")
    public Integer getOrderStatus() {
        return orderStatus;
    }

    public void setOrderStatus(Integer orderStatus) {
        this.orderStatus = orderStatus;
    }

    @Basic
    @Column(name = "out_trade_no")
    public String getOutTradeNo() {
        return outTradeNo;
    }

    public void setOutTradeNo(String outTradeNo) {
        this.outTradeNo = outTradeNo;
    }

    @Basic
    @Column(name = "insert_time")
    public Timestamp getInsertTime() {
        return insertTime;
    }

    public void setInsertTime(Timestamp insertTime) {
        this.insertTime = insertTime;
    }

    @Basic
    @Column(name = "pay_time")
    public Timestamp getPayTime() {
        return payTime;
    }

    public void setPayTime(Timestamp payTime) {
        this.payTime = payTime;
    }

    @Basic
    @Column(name = "tot_amount")
    public Integer getTotAmount() {
        return totAmount;
    }

    public void setTotAmount(Integer totAmount) {
        this.totAmount = totAmount;
    }

    @Basic
    @Column(name = "push_uid")
    public Integer getPushUid() {
        return pushUid;
    }

    public void setPushUid(Integer pushUid) {
        this.pushUid = pushUid;
    }

    @Basic
    @Column(name = "push_split")
    public Integer getPushSplit() {
        return pushSplit;
    }

    public void setPushSplit(Integer pushSplit) {
        this.pushSplit = pushSplit;
    }

    @Basic
    @Column(name = "push_amount")
    public Integer getPushAmount() {
        return pushAmount;
    }

    public void setPushAmount(Integer pushAmount) {
        this.pushAmount = pushAmount;
    }

    @Basic
    @Column(name = "grade_push_uid")
    public Integer getGradePushUid() {
        return gradePushUid;
    }

    public void setGradePushUid(Integer gradePushUid) {
        this.gradePushUid = gradePushUid;
    }

    @Basic
    @Column(name = "grade_split")
    public Integer getGradeSplit() {
        return gradeSplit;
    }

    public void setGradeSplit(Integer gradeSplit) {
        this.gradeSplit = gradeSplit;
    }

    @Basic
    @Column(name = "grade_amount")
    public Integer getGradeAmount() {
        return gradeAmount;
    }

    public void setGradeAmount(Integer gradeAmount) {
        this.gradeAmount = gradeAmount;
    }

    @Basic
    @Column(name = "type")
    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    @Basic
    @Column(name = "is_test")
    public Integer getIsTest() {
        return isTest;
    }

    public void setIsTest(Integer isTest) {
        this.isTest = isTest;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        VipOrder order = (VipOrder) o;
        return Objects.equals(id, order.id) &&
                Objects.equals(uid, order.uid) &&
                Objects.equals(vipType, order.vipType) &&
                Objects.equals(orderStatus, order.orderStatus) &&
                Objects.equals(outTradeNo, order.outTradeNo) &&
                Objects.equals(insertTime, order.insertTime) &&
                Objects.equals(payTime, order.payTime) &&
                Objects.equals(totAmount, order.totAmount) &&
                Objects.equals(pushUid, order.pushUid) &&
                Objects.equals(pushSplit, order.pushSplit) &&
                Objects.equals(pushAmount, order.pushAmount) &&
                Objects.equals(gradePushUid, order.gradePushUid) &&
                Objects.equals(gradeSplit, order.gradeSplit) &&
                Objects.equals(gradeAmount, order.gradeAmount) &&
                Objects.equals(type, order.type);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, uid, vipType, orderStatus, outTradeNo, insertTime, payTime, totAmount, pushUid, pushSplit, pushAmount, gradePushUid, gradeSplit, gradeAmount,type);
    }

    @ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY, optional = true)
    @NotFound(action = NotFoundAction.IGNORE)
    @JoinColumn(name = "uid", referencedColumnName = "id", insertable = false, updatable = false)
    public UserInfo getBuyUser() {
        return buyUser;
    }

    public void setBuyUser(UserInfo buyUser) {
        this.buyUser = buyUser;
    }

    @Transient
    public String getInsertTimeStr() {
        return DateUtil.formatDateTime(insertTime);
    }

    @Transient
    public UserInfo getPushUser() {
        return pushUser;
    }

    public void setPushUser(UserInfo pushUser) {
        this.pushUser = pushUser;
    }

    @Transient
    public UserInfo getGradeUser() {
        return gradeUser;
    }

    public void setGradeUser(UserInfo gradeUser) {
        this.gradeUser = gradeUser;
    }
}
